package cn.getech.data.development.controller.api;

import cn.getech.data.development.api.SendEmailApi;
import cn.getech.data.development.dto.SendEmailMutiPartParamDto;
import cn.getech.data.development.utils.SendEMailUtil;
import cn.getech.data.intelligence.common.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * @ClassName SendEmailApiController
 * @Description TODO
 * @Author Getech
 * @Date 2020/12/24 15:21
 */
@Slf4j
@RestController
public class SendEmailApiController implements SendEmailApi {

    @Autowired
    private SendEMailUtil sendEMailUtil;


    @Override
    public R sendSimpleMail(String mailTo, String mailTittle, String mailText) {
        R r=null;
        try {
            sendEMailUtil.createSimpleMail(mailTo,mailTittle,mailText);
        } catch (Exception e) {
            e.printStackTrace();
            return R.error("发送邮件异常:"+e.getMessage());
        }
        return R.ok();
    }

    @Override
    public R sendMultipartMail(SendEmailMutiPartParamDto sendEmailMutiPartParamDto) {
        R r=null;
        try {
             String filename=   sendEmailMutiPartParamDto.getFilename();
             String mailTo=   sendEmailMutiPartParamDto.getMailTo();
             String msg=   sendEmailMutiPartParamDto.getMsg();
             String mailTitle=   sendEmailMutiPartParamDto.getMailTitle();
             HashMap<String,Object>  paramsData=new HashMap();
             paramsData.put("msg",msg);
             paramsData.put("filename",filename);
            sendEMailUtil.createMultipartMail(mailTo,mailTitle,paramsData);
        } catch (Exception e) {
            e.printStackTrace();
            return R.error("发送邮件异常:"+e.getMessage());
        }
        return R.ok();
    }
}
